#include <header.h>

void my_read(int file_fd, char *buf,  int len){

    int size = 0;
    while(size < len){
        ssize_t ret = read(file_fd, buf+size, len-size);
        size += ret;
    }

}
int main(){

    while(1){
        int file_fd = open("1.txt", O_RDWR);
        ssize_t num = 0;
        my_read(file_fd, (char *)&num, sizeof(ssize_t));
        printf("num: %ld \n", num);
        char buf[100]= {0};
        my_read(file_fd, buf, num);
        printf("buf:%s \n", buf);

        ftruncate(file_fd, 0);
        close(file_fd);


        int file_fd2 = open("1.txt", O_RDWR);
        bzero(buf, sizeof(buf));
        ssize_t ret = read(STDIN_FILENO, buf, sizeof(buf));
        write(file_fd2, &ret, sizeof(ssize_t));
        write(file_fd2, buf, ret);
        close(file_fd2);


    }
    return 0;
}

